<?php
dl('php_pdo_sqlite.dll');

    //open the database
	$db = createDB();
	addToDB($db,"a","b",1);

    $result = $db->query('SELECT * FROM AdminDB');
    foreach($result as $row)
    {
      print "<tr><td>".$row['Id']."</td>\n";
      print "<td>".$row['username']."</td>\n";
      print "<td>".$row['password']."</td>\n";
      print "<td>".$row['groupID']."</td></tr>\n";
    }
    print "</table>";

    $db = NULL;
  

  
  function createDB()
  {
      $db = new PDO('sqlite:AdminDb_PDO.sqlite');
      $db->exec("CREATE TABLE IF NOT EXISTS AdminDB (_id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT, groupID INTEGER)");    
	  return $db;	
   }
  function addToDB($db,$user,$pw,$id)
  {
		$db->exec("INSERT INTO AdminDB (username, password, groupID) VALUES ('$user', '$pw', '$id');");
  }
  
  function createEventDB()
  {
      $db = new PDO('sqlite:EventDb_PDO.sqlite');
      $db->exec("CREATE TABLE IF NOT EXISTS EventDB(_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, organizationId INTEGER, month INTEGER, day INTEGER, year INTEGER, startTime TEXT NOT NULL, finishTime TEXT,location TEXT,description TEXT,imageURL TEXT,facebookURL TEXT,coSponsors TEXT,volunteerIndexes TEXT)");    
	  return $db;	
   }
  function addToEventDB($db,$title,$orgID,$month, $day, $year, $start, $finish, $loc, $desc,$img, $fb, $cosponsor, $vols)
  {
		$db->exec("INSERT INTO EventDB (title, organizationId, month, day, year, startTime, finishTime, location, description, imageURL, facebookURL, coSponsors, volunteerIndexes) VALUES ('$db','$title','$orgID','$month', '$day', '$year', '$start', '$finish', '$loc', '$desc','$img', '$fb', '$cosponsor', '$vols');");
  }
  
  function createVolunteerDB()
  {
      $db = new PDO('sqlite:VolunteerDb_PDO.sqlite');
      $db->exec("CREATE TABLE IF NOT EXISTS VolunteerDB(_id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT NOT NULL,email TEXT NOT NULL,org1 INTEGER,org2 INTEGER,org3 INTEGER,org4 INTEGER,org5 INTEGER,org6 INTEGER,org7 INTEGER,org8 INTEGER)");    
	  return $db;
   }
  function addToVolunteerDB($db,$title,$email,$org1,$org2,$org3,$org4,$org5,$org6,$org7,$org8)
  {
		$db->exec("INSERT INTO AdminDB (title, email, org1,org2,org3,org4,org5,org6,org7,org8) VALUES ('$db','$title','$email','$org1','$org2','$org3','$org4','$org5','$org6','$org7','$org8');");
  }
  
  function createSuggestionDB()
  {
      $db = new PDO('sqlite:SuggestionDb_PDO.sqlite');
      $db->exec("CREATE TABLE IF NOT EXISTS SuggestionDB(_id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT NOT NULL,orgId INTEGER NOT NULL,description TEXT,email TEXT,votes INTEGER)");    
	  return $db;	
   }
  function addToSuggestionDB($db,$title,$orgId,$desc, $email, $votes)
  {
		$db->exec("INSERT INTO AdminDB (title, orgId, description, email, votes) VALUES ('$db','$title','$orgId','$desc', '$email', '$votes');");
  }
  
  
  
?>